﻿
<!DOCTYPE html>
<html>
<head>
	<title>课程评估</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
<link rel="stylesheet" type="text/css" href="/framework/vue/weui.min.css">
<link rel="stylesheet" type="text/css" href="/system/views/wenjuan/wenjuan.css">

</head>
<body>

<div id="app" style="padding: 0" >
<div class="container" style=" overflow:hidden;min-height: 600px;">
<h1 v-html="totle.org_name"></h1>
<br />
<h4 style="text-align:center;">参与人：<strong style="font-size:24px;" v-html="totle.student_number"></strong>个，总平均分：<strong style="color:#39f;font-size:24px;" v-html="totle.student_number>0?(totle.org_id/totle.student_number):0"></strong>分</h4>
<br />
<br />
<div v-for="(item,index) in echartList" :key="item.coursedId">
<!--	<div class="weui-loadmore weui-loadmore_line">
	            <span class="weui-loadmore__tips">{{item.courseName}}</span>
	</div>-->
   <div :id="'echart_'+item.coursedId" style=" width:100%; height:400px; float:left;"></div>
</div>
<!-- loading toast -->

</div>
</div>
<div class="weui-footer">
            <p class="weui-footer__text">Copyright © </p>
        </div>


<script src="/framework/angular.min.js"></script>
<script type="text/javascript" src="/framework/vue/zepto.min.js"></script>
<script src="/framework/lodash.min.js" type="text/javascript"></script>
<script src="/framework/echarts/echarts.min.js" type="text/javascript"></script>
<script src="/framework/restangular/restangular.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/framework/angular-toastr/angular-toastr.min.js"></script>
<script type="text/javascript" src="/framework/angular-toastr/angular-toastr.tpls.min.js"></script>
    <script src="/framework/angular-wang-editor/dist/js/lib/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="/framework/vue/vue.min.js" type="text/javascript" ></script>
<script src="/system/service/common.js" type="text/javascript"></script>    
<script type="text/javascript">
var yuming ="";
try{
yuming = commonUrl;
}catch(e){
alert("ee");
}

var wenjuan ={};
var echartList=[];
var dati =[];
var user = {};//登录人信息，注意需要企业ID,组织架构ID
var vm;
var xid = QueryString("xid");
var key = QueryString("key");
var totle={org_id:0,student_number:0,org_name:"讲师评估问卷"};
//界面初始化
$(function(){
    user = GetlocalStorage("userinfo");
    echartList=[]

    getAjax(yuming+"/questionnaire/findGradeNumber",{qid:key,gradeid:xid,orgId:user.organization_ID,xtype:3},function(data){
      if(data.errorcode == "0"){
        totle=data.data;
        totle.org_id==undefined?0:parseInt(totle.org_id);//总分
        totle.student_number==undefined?0:parseInt(totle.student_number);//总人数
      }
     
      else{
        alert("读取错误"+data.errorcode);
      }
       
       getAjax(yuming+"/questionnaire/CourseSoure",{qid:key,gradeId:xid,orgId:user.organization_ID},function(data){
      if(data.errorcode == "0"){
       // wenjuan = JSON.parse(data.datas);
        echartList=data.datas;
        if(echartList.length<=0){
             alert("该班级还未添加课程！");
        }else{
            echartList.forEach(function(data,index){
                data.lecturer=JSON.parse(data.lecturer);
                data.group=JSON.parse(data.group);
            });
            vmchushi();
            makingEchart();
        }
      }
      else{
        alert("读取错误"+data.errorcode);
      }
    });  
    });   
     
});
  //***************************************************************开始绘图********************************************************/
  function makingEchart(){
   echartList.forEach(function(data,index){
          var nameList=[];
          var valueList=[];
          var count=0;//总平均分
         data.group[0].group.forEach(function(data2,index2){
            nameList.push(data2.qtitle);
            count+=data2.qselection[0].score;
            valueList.push(data2.qselection[0].score);
         });
          
          var dom = document.getElementById("echart_"+data.coursedId);
             var myChart = echarts.init(dom);
			 
			//	title: {
            //        text: data.courseName,
            //        subtext: "讲师："+data.lecturer.user_Name+"（总平均分："+count+"）",
             //   },
            //$(".dx").remove();
             option = {
             	title: {
                    text: data.courseName,
                    subtext: "讲师："+data.lecturer.user_Name+"（总平均分："+count+"）",
                },

                    xAxis: {
                        type: 'category',
                        data: nameList,
                        axisLabel: {  
                                interval: 0,  
                                formatter:function(value,index)  
                                {  
                                    debugger  
                                    if (index % 2 != 0) {  
                                        return '\n\n' + value;  
                                    }  
                                    else {  
                                        return value;  
                                    }  
                                }  
                            }
                    },
                    yAxis: {
                        type: 'value',
                        
                    },
grid: { // 控制图的大小，调整下面这些值就可以，
             x: 50,
             x2: 50,
             y2: 50,// y2可以控制 X轴跟Zoom控件之间的间隔，避免以为倾斜后造成 label重叠到zoom上
         },
                    series: [{
                        data: valueList,
                        type: 'bar'
                    }]
                };

            if (option && typeof option === "object") {
                myChart.setOption(option, true);
            }
        
    }); 
  }

 //***************************************************************绘图结束********************************************************/
function vmchushi(){
	vm = new Vue({
		el: '#app',
  		data: {
  			echartList:echartList,//题目对象
            totle:totle,
  			loading:false,
  		},
  		methods: {
            jindutiao:function(sel,qid){
            }
  		},//注册函数
  		directives:{//注册指令
  			
  		}
	});
}

//用于生成uuid
function guid() {
	function S4() {
	    return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
	}
	 return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
/**
  *工具 || 获得URL GET参数
 */
function QueryString(fieldName) {
    /// <summary>
    ///   获得URL GET参数
    /// </summary>
    /// <param name="fieldName" type="String">
    ///   参数名
    /// </param>
    /// <returns type="void" />如果不存在返回NULL
    var reg = new RegExp("(^|&)" + fieldName.toLowerCase() + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}
//**********************************************************************
//全局异步请求数据
//**********************************************************************
document.writeln("<div id=\'loadingToast\' style=\'display:none;\'>");
document.writeln("        <div class=\'weui-mask_transparent\'></div>");
document.writeln("        <div class=\'weui-toast\'>");
document.writeln("            <i class=\'weui-loading weui-icon_toast\'></i>");
document.writeln("            <p class=\'weui-toast__content\'>数据加载中</p>");
document.writeln("        </div>");
document.writeln("    </div>");
function getAjax(url, parm, callBack, callBackError, callBackType, mode, istongbu) {
    $("#loadingToast").show();
    var token = "userinfo_token is none";
    if (callBackType == null || callBackType == "" || callBackType == undefined)
        callBackType = "text";
    if (mode == null || mode == "" || mode == undefined)
        mode = "post";
    if (istongbu != undefined && !istongbu) {
        istongbu = false;
    } else {
        istongbu = true;
    }
    try {
        $.ajax({
            type: mode,
            beforeSend: function (xhr) {
                if (!QueryString("courseId")) {
                    token = strToJson(GetlocalStorage("userinfo_token"), token);
                    xhr.setRequestHeader("X-Session-Token", token.token);
                }
            },
            //手机端需要加上token验证
            headers: {
                //"Accept": "text/plain; charset=utf-8",
                //"Content-Type": "text/plain; charset=utf-8",
                "Accept": "application/json, text/javascript, */*; charset=utf-8",
                "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
            },
            async: istongbu,
            url: url,
            data: parm,
            dataType: callBackType,
            cache: false,
            success: function (msg, status, xhr) {
                pedding = false;
                $("#loadingToast").hide();
                msg = strToJson(msg);
                if (msg && msg.errorcode && (msg.errorcode == 35 || msg.errorcode == 36)) {
                    alert("身份验证已失效，请重新登录！");
                } else {
                    callBack(msg);
                    //  console.log(msg);
                }
            },
            error: function (err) {
                // $.hideIndicator(); //loading
                if (callBackError != undefined && callBackError != null && callBackError != "")
                    callBackError(err);
                // $.alert(err);
                console.log('请求服务器错误！');
                pedding = false;
                console.error("服务器访问异常：" + err.readyState);
                $("#loadingToast").hide();
            }
        });

    }
    catch (error) {
        console.log(error);
        alert("请求错误,请刷新重试！");
        $("#loadingToast").hide();
    }
}
/**
* 工具 || 获得本地存储
*/
function GetlocalStorage(name) {
    // / <summary>
    // / 获得本地数据
    // / </summary>
    if (window.localStorage) {
        var value = localStorage.getItem(name);
        if (value != null) {
            return JSON.parse(value);
        } else {
            return value;
        }
    } else {
        alert("您需要升级浏览器");
    }
}
/**
*工具 || 存储
*/
function SetlocalStorage(name, obj) {
    // / <summary>
    // / 重写本地数据
    // / </summary>
    if (window.localStorage) {
        try {
            localStorage.setItem(name, JSON.stringify(obj));
        }
        catch (oException) {
            if (oException.name == 'QuotaExceededError') {
                console.log('超出本地存储限额！');
                //如果历史信息不重要了，可清空后再设置
                localStorage.clear();
                localStorage.setItem(name, JSON.stringify(obj));
            }
        }
    } else {
        alert("您需要升级浏览器才能够进行学习");
    }
}
//字符转对象
function strToJson(str) {
    try {
        if (str != null && str != "" && str != undefined) {
            return JSON.parse(str);
        } else {
            return null;
        }
    } catch (e) {
        return str;
    }
}
</script>
</body>
</html>